package org.mashart.pink.m.ws;

import org.mashart.pink.m.store.RecordManager;

/**
 * The connector that stores the GPS data in RecordStore, which is a simple persistent storage for J2ME application.
 */
public class RecordStoreConnector implements WsConnector{

    /**
     * Record Manager, implements the operation on record store.
     */
    private RecordManager recordManager;

    /**
     * Configure.
     * @return
     */
    public int configure(){
        // Do nothing
        return 1;
    }

    /**
     * Initialize the record store.
     * @return
     */
    public int initialize(){
        recordManager = RecordManager.getInstance();
        return 1;
    }

    /**
     * Store the data in bytes.
     * @param b
     * @return
     */
    public int push(String s){
        return recordManager.insert(s.getBytes());
    }

    /**
     * Store the action command in bytes.
     * @param b
     * @return
     */
    public int pushAction(String action){
        return push("action=" + action);
    }

    /**
     * Close the record store. The records should remains on the mobile phone,
     * until the <code>RecordStoreConnector</code> is initialzed again.
     * However, depending on the implementation of the mobilephone,
     * it is possible that the RecordStore can not survive through battery changes, failures, or reboots.
     * @return
     */
    public int terminate(){
        return 1;
    }
}
